package com.cloudsigns.factorymanager2.engineering.presenter;


import com.cloudsigns.factorymanager2.engineering.IView.IReceiveEngineeringOrderListView;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.model.IReceiveEngineeringOrderListModel;
import com.cloudsigns.factorymanager2.engineering.model.ReceiveEngineeringOrderListModel;

import java.util.List;

/**
 * 工单列表接口
 * Created by tony on 2018/3/3.
 */

public class ReceiveEngineeringOrderListPresent {
    private IReceiveEngineeringOrderListView view;
    private IReceiveEngineeringOrderListModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public ReceiveEngineeringOrderListPresent(IReceiveEngineeringOrderListView view) {
        this.view = view;
        this.model = new ReceiveEngineeringOrderListModel();
    }

    public void getReceiveEngineeringOrderList() {
        view.showLoading();

        model.getReceiveEngineeringOrderList(new ReceiveEngineeringOrderListModel.OnReceiveEngineeringOrderListener() {
            @Override
            public void getDataSuccessed(final List<OrderParentBean> orderParentBeanList, final List<OrderParentBean> engineeringOrderBeanList_status_send, final List<OrderParentBean> engineeringOrderBeanList_status_receives, final List<OrderParentBean> engineeringOrderBeanList_status_returns, final List<OrderParentBean> engineeringOrderBeanList_status_success) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showData(orderParentBeanList, engineeringOrderBeanList_status_send, engineeringOrderBeanList_status_receives, engineeringOrderBeanList_status_returns, engineeringOrderBeanList_status_success);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
